/*
 * Copyright (C) 2018 Hisilicon Limited.
 *
 * this program is for hisi chip mini pcie nvme
 *
 * This program is free software; you can redistribute it and /or modify it
 * under the terms of the GNU General Public License as published by the Free
 * Software Foundation; either version 2 of the License, or (at your option)
 * any later version
 */

#include <asm/io.h>

#include "apb_drv.h"


#define RC_EP_MODE_REG 0x1100CE088
#define RC_EP_MODE_REG_SIZE 0x4
#define RC_EP_MODE_REG_MODE_OFFSET 3
#define RC_EP_MODE_REG_MODE_MASK (0x1 << RC_EP_MODE_REG_MODE_OFFSET)


int devdrv_get_devid_by_bus(unsigned char bus_number, int *devid)
{
    (void)bus_number;
    *devid = 0;

    return 0;
}


int agentdrv_get_rc_ep_mode(u32 *mode)
{
    void __iomem *io_base;
    u32 val;

    io_base = ioremap(RC_EP_MODE_REG, RC_EP_MODE_REG_SIZE);
    if (!io_base) {
        devdrv_err("ioremap RC EP reg fail\n");
        return -ENOMEM;
    }
    devdrv_apb_reg_rd(io_base, 0, &val);
    iounmap(io_base);

    if (val & RC_EP_MODE_REG_MODE_MASK)
        *mode = DEVDRV_PCIE_EP_MODE;
    else
        *mode = DEVDRV_PCIE_RC_MODE;

    return 0;
}
EXPORT_SYMBOL(agentdrv_get_rc_ep_mode);
